var a = getApp();

Page({
    data: {
        paramsId: 0,
        searchText: "",
        explainFlag: !1,
        tabs_list: [],
        tabs_index: 0,
        banner_list: [],
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        explainText: "",
        firstLoading: !1,
        shareConfig: {},
        Height: 0,
        LastHeight: 0
    },
    onLoad: function(a) {
        a.id && (this.data.paramsId = a.id), this.getListData(!0);
    },
    setExplainFlag: function() {
        this.setData({
            explainFlag: !this.data.explainFlag
        });
    },
    onReady: function() {},
    imgHeight: function(a) {
        var t = wx.getSystemInfoSync().windowWidth * a.detail.height / a.detail.width + "px";
        parseInt(t) > this.data.LastHeight && (this.setData({
            Height: t
        }), this.data.LastHeight = parseInt(t));
    },
    setTabsIndex: function(a) {
        console.log(a);
        var t = a.detail.index;
        this.data.tabs_index = t, this.getListData();
    },
    onShow: function() {},
    tapUrl: function(a) {
        var t = a.currentTarget.dataset.url;
        if ("" == t) return !1;
        try {
            wx.navigateTo({
                url: t
            });
        } catch (a) {
            console.log(a);
        }
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {
        var a = wx.getStorageSync("yz_uid"), t = "";
        return a && (t = a), {
            title: this.data.shareConfig.share_title,
            path: "/packageI/groupWork/groupWorkIndex/groupWorkIndex?&mid=" + t,
            imageUrl: this.data.shareConfig.share_thumb
        };
    },
    initPage: function() {
        this.setData({
            listData: [],
            networkLoading: !1
        }), this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0;
    },
    getListData: function(t) {
        var e = this;
        this.initPage();
        var i = a.getNetAddresss("plugin.group-work.frontend.controllers.page.index"), s = this.data, n = s.tabs_index, o = s.tabs_list, r = s.searchText;
        0 != o.length ? i += "&search[category_id]=" + o[n].id : i += "&search[category_id]=" + this.data.paramsId, 
        "" != r && (i += "&search[title]=" + r), a._postNetWork({
            url: i,
            success: function(i) {
                var s = i.data;
                if (1 != s.result) return a.tips(s.msg);
                var n = {};
                e.data.firstLoading || (n.tabs_list = [ {
                    title: "全部",
                    id: 0
                } ].concat(s.data.category_list), t && n.tabs_list.forEach(function(a, t) {
                    a.id == e.data.paramsId && e.setData({
                        tabs_index: t
                    });
                }), n.banner_list = s.data.banner_list, n.explainText = s.data.explain, n.firstLoading = !0, 
                wx.setNavigationBarTitle({
                    title: s.data.costum_name
                }), e.data.shareConfig.share_title = s.data.share_title, e.data.shareConfig.share_thumb = s.data.share_thumb), 
                n.isLoadMore = !0, n.total_page = s.data.page_list.last_page, n.listData = s.data.page_list.data, 
                n.networkLoading = !0, e.setData(n), e.data.total_page || (e.data.total_page = 0);
            }
        });
    },
    getMoreData: function() {
        var t = this, e = a.getNetAddresss("plugin.group-work.frontend.controllers.page.index");
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page++;
            var i = {
                page: this.data.page
            }, s = this.data, n = s.tabs_index, o = s.tabs_list, r = s.searchText;
            0 != o.length && (e += "&search[category_id]=" + o[n].id), "" != r && (e += "&search[title]=" + r), 
            a._getNetWork({
                url: e,
                data: i,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.data.isLoadMore = !0;
                        var i = e.data.page_list.data;
                        t.setData({
                            listData: t.data.listData.concat(i)
                        });
                    } else t.data.isLoadMore = !1, t.data.page--;
                }
            });
        }
    },
    onSearch: function(a) {
        console.log(a);
        var t = a.detail.value;
        this.data.searchText = t, this.getListData();
    },
    clearSearch: function() {
        this.setData({
            searchText: ""
        });
    },
    gotoUrl: function(a) {
        a.detail && wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?activity_id=" + a.detail + "&name=99"
        });
    }
});